package com.itheima.mapper;

import com.itheima.domain.EmpQueryParam;
import com.itheima.domain.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

    //=============================分页查询-原始方式==================================
    /*@Select("select count(*) from emp e left join dept d on  e.dept_id = d.id ")
    Long count();

    @Select("select e.*,d.name deptName  from emp e left join dept d on  e.dept_id = d.id order by e.update_time desc limit #{start},#{pageSize}")
    List<Emp> list(int start, Integer pageSize);*/

    //=============================分页查询-PageHelper方式==================================
//    @Select("select e.*,d.name deptName  from emp e left join dept d on  e.dept_id = d.id order by e.update_time desc")
//    List<Emp> list();

    /**
     * 分页条件查询
     * @param name
     * @param gender
     * @param begin
     * @param end
     * @return
     */
//    List<Emp> list(String name, Integer gender, LocalDate begin, LocalDate end);

    /**
     * 分页条件查询程序优化-参数封装
     * @param empQueryParam
     * @return
     */
    List<Emp> list(EmpQueryParam empQueryParam);


    @Insert("insert into emp(username,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id") // 设置主键回填
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    Emp getById(Integer id);

//    @Update("update emp set username=#{username},name=#{name},gender=#{gender},phone=#{phone},job=#{job},salary=#{salary},image=#{image},entry_date=#{entryDate},dept_id=#{deptId},update_time=#{updateTime} where id=#{id}")
    void updateById(Emp emp);

    List<Map<String, Object>> empJobData();

    List<Map<String, Object>> empGenderData();

    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp selectByUsernameAndPassword(@Param("username") String username,
                                    @Param("password") String password);
}
